﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using System.Collections.Generic;
using System.Collections.Specialized;


using PowerCreator.LMS.User.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Web.User;
using PowerCreator.LMS.Web.DL.Project;
using PowerCreator.LMS.DL.Project.Entity;
using PowerCreator.LMS.Web.DL.Project;

public partial class Theme_3_Register : System.Web.UI.Page
{
    VOTOLearner vo = new VOTOLearner();
    TOLearner obj = new TOLearner();
    TOSchoolGroup objschool = new TOSchoolGroup();
    protected  PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    protected String returnValue;
    LogicServer.NetMeetingClass objNetMeetingClass;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = config.GetLanagerValueByKey("SysManagerRegistor", PowerCreator.LMS.Language.LanagetItemType.Page);
        if (!IsPostBack)
        {
            InitPage();
            this.btn_AddNew.Attributes.Add("OnClick", "return checkForm()");
            
            BinderDepartmentClass();
            if (PowerCreator.LMS.Web.Config.WebConfig.IsUseNetMeeting)
            {
                objNetMeetingClass = new LogicServer.NetMeetingClass();
            }

        }
       
    }
   


    protected  void InitPage()
    {

        btn_AddNew.Text = config.GetLanagerValueByKey("btn_EditNew", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Reset.Text = config.GetLanagerValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
    }


    /// <summary>
    /// 检查页面数据
    /// </summary>
    /// <returns></returns>
    private bool CheckPageData()
    {
        if (!(txt_UserPwd.Text.ToString() == txt_DBUserPwd.Text.ToString()))
        {
            lab_dbPwd.Text = config.GetLanagerValueByKey("theme_Register_Msg5", PowerCreator.LMS.Language.LanagetItemType.Page) ;
            return false;
        } 

        string search = string.Format("UserName = '{0}'", txt_UserName.Text);
        if (obj.Count(search) != 0)
        {
            lbl_AddStudent_msg_username.Text = config.GetLanagerValueByKey("theme_Register_Msg2", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }

        //if (!string.IsNullOrEmpty(txt_Birth.Text))
        //{
        //    if (!TimeUtils.IsDateTime(txt_Birth.Text.Trim()))
        //    {
        //        lab_Birth_css.Text = config.GetLanagerValueByKey("theme_Register_Msg3", PowerCreator.LMS.Language.LanagetItemType.Page);
        //        return false;
        //    }
        //}  
        if (ddl_Class.Items.Count == 0)
        {
            lbl_addstudent_selectdepartment.Text = config.GetLanagerValueByKey("theme_Register_Msg4", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }

        return true;
    }

   
    private void BinderDepartmentClass()
    {
        //if(ddl_Department.SelectedValue)

        string search = " SchoolGroup_Id not in (select SchoolGroupParentId from TO_SchoolGroup)";
        DataTable dt = objschool.Query(search);
        ddl_Class.DataSource = dt;
        ddl_Class.DataTextField = "SchoolGroupName";
        ddl_Class.DataValueField = "SchoolGroup_Id";
        ddl_Class.DataBind();
    }


    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string msgWorkOK = "";
        if (!CheckPageData()) return;
        vo.UserName = txt_UserName.Text;
        vo.UserPwd = PowerCreator.LMS.Common.Utils.MD5Helper.GetMD5(txt_UserPwd.Text);

        if (!string.IsNullOrEmpty(ddl_Class.SelectedValue.ToString()))
            vo.School = int.Parse(ddl_Class.SelectedValue.ToString());

        if (radbtn_Female.Checked)
            vo.Sex = true;
        else
            vo.Sex = false;
        vo.Name = txt_RealName.Text.Trim();

        if (obj.Add(vo))
        {

            string url = "Default.aspx";
            //string msgWorkOK=config.GetLanagerValueByKey("Msg_ManagerQuestion_WorkOK", PowerCreator.LMS.Language.LanagetItemType.Page);
            Script.ShowMsgRedirectUrl("注册成功！",url);
        }

      
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string url = "Default.aspx";
        Script.RedirectURL(url);
    }
    protected void ddl_Department_SelectedIndexChanged(object sender, EventArgs e)
    {
        BinderDepartmentClass();
    }

    protected void lnkbtn_EN_Click(object sender, EventArgs e)
    {
        Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_LANGEID] = "1";
    }
    protected void lnkbtn_CN_Click(object sender, EventArgs e)
    {
        Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_LANGEID] = "0";
    }


}
